# -*- coding: utf-8 -*-
# @Create_time   : :
# @Author        :kumiler
# @emial         :lukunming@jtexpress.com
# @File          :.py
# @Desc          :


from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
# from spmi_fee_domain.dwd.dwd_spmi_piece_bill_base_dt import spmi_dwd__dwd_spmi_piece_bill_base_dt

# 派件费

# 费用类型 201
spmi_dm__dm_spmi_piece_bill_fee_aggr1_dt = SparkSqlOperator(
    task_id='spmi_dm__dm_spmi_piece_bill_fee_aggr1_dt',
    email=['lukunmingn@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='spmi_dm__dm_spmi_piece_bill_fee_aggr1_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi_fee_domain/dm/dm_spmi_piece_bill_fee_aggr_dt/execute1.sql',
    pool_slots=2,
    driver_cores=2,
    driver_memory='6G',
    executor_cores=4,
    executor_memory='12G',
    num_executors=90,
    conf={'spark.dynamicAllocation.enabled'                  : 'true',
          'spark.shuffle.service.enabled'                    : 'true',
          'spark.dynamicAllocation.maxExecutors'             : 100,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 30,
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',
          'spark.executor.memoryOverhead'                    : '4G',
          'spark.yarn.maxAppAttempts'                        : 1,
          'spark.sql.shuffle.partitions': 1000,
          'spark.shuffle.consolidateFiles': 'true',
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer':'64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2'
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 300,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=70),
    retries=0,
)

# spmi_dm__dm_spmi_piece_bill_fee_aggr1_dt << spmi_dwd__dwd_spmi_piece_bill_incr_dt


# 费用类型 203
spmi_dm__dm_spmi_piece_bill_fee_aggr3_dt = SparkSqlOperator(
    task_id='spmi_dm__dm_spmi_piece_bill_fee_aggr3_dt',
    email=['lukunmingn@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='spmi_dm__dm_spmi_piece_bill_fee_aggr3_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi_fee_domain/dm/dm_spmi_piece_bill_fee_aggr_dt/execute3.sql',
    pool_slots=2,
    driver_cores=2,
    driver_memory='6G',
    executor_cores=5,
    executor_memory='12G',
    num_executors=60,
    conf={'spark.dynamicAllocation.enabled'                  : 'true',
          'spark.shuffle.service.enabled'                    : 'true',
          'spark.dynamicAllocation.maxExecutors'             : 80,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 30,
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',
          'spark.executor.memoryOverhead'                    : '3G',
          'spark.yarn.maxAppAttempts'                        : 1,
          'spark.sql.shuffle.partitions': 1000,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 300,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
    retries=0,
)

# spmi_dm__dm_spmi_piece_bill_fee_aggr3_dt << spmi_dwd__dwd_spmi_piece_bill_incr_dt

# 费用类型 205
spmi_dm__dm_spmi_piece_bill_fee_aggr5_dt = SparkSqlOperator(
    task_id='spmi_dm__dm_spmi_piece_bill_fee_aggr5_dt',
    email=['lukunmingn@jtexpress.com','yl_bigdata@yl-scm.com'],
    master='yarn',
    name='spmi_dm__dm_spmi_piece_bill_fee_aggr5_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi_fee_domain/dm/dm_spmi_piece_bill_fee_aggr_dt/execute5.sql',
    pool_slots=2,
    driver_cores=2,
    driver_memory='6G',
    executor_cores=5,
    executor_memory='12G',
    num_executors=80,
    conf={'spark.dynamicAllocation.enabled'                  : 'true',
          'spark.shuffle.service.enabled'                    : 'true',
          'spark.dynamicAllocation.maxExecutors'             : 90,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 50,
          'spark.sql.sources.partitionOverwriteMode'         : 'dynamic',
          'spark.executor.memoryOverhead'                    : '3G',
          'spark.yarn.maxAppAttempts'                        : 1,
          'spark.sql.shuffle.partitions': 1200,
          },
    hiveconf={'hive.exec.dynamic.partition'             : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'        : 'nonstrict',
              'hive.exec.max.dynamic.partitions'        : 300,  # 最大分区
              'hive.exec.max.dynamic.partitions.pernode': 300,  # 最大分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
    retries=0,
)

# spmi_dm__dm_spmi_piece_bill_fee_aggr5_dt << spmi_dwd__dwd_spmi_piece_bill_incr_dt